#include "orangepch.h"
#include "OpenGLBuffer.h"
#include "GLFW/glfw3.h"
#include "glad/glad.h"
namespace Orange
{
    OpenGLVertexBuffer::OpenGLVertexBuffer(float *vertexs, uint32_t size)
    {
        glCreateBuffers(1, &m_RendererId);
        glBindBuffer(GL_ARRAY_BUFFER, m_RendererId);
        glBufferData(GL_ARRAY_BUFFER, size, vertexs, GL_STATIC_DRAW);
    }
    OpenGLVertexBuffer::~OpenGLVertexBuffer()
    {
        glDeleteBuffers(1, &m_RendererId);
    }
    void OpenGLVertexBuffer::Bind()
    {
        glBindBuffer(GL_ARRAY_BUFFER, m_RendererId);
    }
    void OpenGLVertexBuffer::UnBind()
    {
        glBindBuffer(GL_ARRAY_BUFFER, 0);
    }

    void OpenGLVertexBuffer::SetLayout(ShaderLayout &layout)
    {
        m_Layout = layout;
    };
    ShaderLayout &OpenGLVertexBuffer::GetLayout()
    {
        return m_Layout;
    };

    OpenGLIndexBuffer::OpenGLIndexBuffer(uint32_t *indexes, uint32_t count):m_Count(count)
    {
        glCreateBuffers(1, &m_RendererId);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererId);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(uint32_t), indexes, GL_STATIC_DRAW);
    }
    OpenGLIndexBuffer::~OpenGLIndexBuffer()
    {
        glDeleteBuffers(1, &m_RendererId);
    }
    void OpenGLIndexBuffer::Bind()
    {
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererId);
    }

    void OpenGLIndexBuffer::UnBind()
    {
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    }

    uint32_t OpenGLIndexBuffer::GetCount() const {
        return m_Count;
    }

}